(function(){BX.namespace("BX.Main.UserConsent");BX.Main.UserConsent.Edit=function(t){this.isSaved=t.isSaved;this.mess=t.mess;this.listDomIds=t.listDomIds;this.container=BX(this.listDomIds["formContainerId"]);this.typeNode=this.container.querySelector("[data-bx-type-input]");this.langNode=this.container.querySelector("[data-bx-lang-input]");this.initialLang=this.langNode.value&&this.typeNode.value==="C"?this.langNode.value:null;this.typeSelectorNode=this.container.querySelector("[data-bx-type-selector]");this.typeViewNode=this.container.querySelector("[data-bx-type-view]");this.dataProviderNode=this.container.querySelector("[data-bx-data-provider]");this.dataProviderInputNode=this.container.querySelector("[data-bx-data-provider-input]");this.dataProviderUrlNode=this.container.querySelector("[data-bx-data-provider-url]");this.fieldListNodes=this.container.querySelectorAll("[data-bx-fields]");this.fieldListNodes=BX.convert.nodeListToArray(this.fieldListNodes);BX.bind(this.typeViewNode,"click",this.showAgreementText.bind(this));BX.bind(this.typeSelectorNode,"change",this.onTypeChange.bind(this));BX.fireEvent(this.typeSelectorNode,"change");BX.bind(this.dataProviderInputNode,"change",this.onDataProviderChange.bind(this));BX.bind(this.dataProviderUrlNode,"click",this.onDataProviderUrlClick.bind(this));BX.fireEvent(this.dataProviderInputNode,"change");this.getFields(this.container).forEach((function(t){if(!t.togglerNode||!t.toggledNode||!t.inputNode){return}BX.bind(t.togglerNode,"click",(function(){t.toggledNode.style.display=t.togglerNode.checked?"":"none";t.inputNode.disabled=!t.togglerNode.checked}))}));if(top!=window&&top.BX){BX.bind(BX("MAIN_USER_CONSENT_EDIT_BACK_TO_LIST"),"click",(function(t){if(!top||!top.BX){return}top.BX.onCustomEvent(top,"main-user-consent-to-list",[]);t.preventDefault()}))}if(this.isSaved){this.sendEventMessageAboutSave()}};BX.Main.UserConsent.Edit.prototype.showTextTab=function(){this.container.style.display="";if(BX(this.listDomIds["listContainerId"])){BX(this.listDomIds["listContainerId"]).style.display="none"}BX(this.listDomIds["fieldNameId"]).style.display="";BX(this.listDomIds["fieldTypeId"]).style.display="";BX(this.listDomIds["fieldProviderId"]).style.display="";this.showTab("text")};BX.Main.UserConsent.Edit.prototype.showSettingsTab=function(){this.container.style.display="";if(BX(this.listDomIds["listContainerId"])){BX(this.listDomIds["listContainerId"]).style.display="none"}BX(this.listDomIds["fieldNameId"]).style.display="none";BX(this.listDomIds["fieldTypeId"]).style.display="none";BX(this.listDomIds["fieldProviderId"]).style.display="none";this.showTab("settings")};BX.Main.UserConsent.Edit.prototype.showListTab=function(){this.container.style.display="none";if(BX(this.listDomIds["listContainerId"])){BX(this.listDomIds["listContainerId"]).style.display=""}};BX.Main.UserConsent.Edit.prototype.showTab=function(t){this.fieldListNodes.forEach(function(e){if(this.isTypeVisible(e)){var i=e.querySelectorAll("[data-bx-field]");var o=BX.convert.nodeListToArray(i);o.forEach(function(e){if(e.getAttribute("data-bx-tab")===t){e.style.display=""}else{e.style.display="none"}}.bind(this))}}.bind(this))};BX.Main.UserConsent.Edit.prototype.submit=function(){BX(this.listDomIds["formId"]).submit()};BX.Main.UserConsent.Edit.prototype.sendEventMessageAboutSave=function(){if(window.top===window){return}if(!window.top.BX){return}window.top.BX.onCustomEvent(window.top,"main-user-consent-saved",[])};BX.Main.UserConsent.Edit.prototype.onDataProviderChange=function(){var t=this.dataProviderInputNode.options[this.dataProviderInputNode.selectedIndex];var e=t.getAttribute("data-bx-data");var i=t.getAttribute("data-bx-edit-url");if(e){try{e=JSON.parse(e)}catch(t){e=null}}var o={name:t.innerText};this.dataProviderUrlNode.style.display=i?"":"none";this.dataProviderUrlNode.dataset.href=i;this.showFieldsDataProvider(e,o)};BX.Main.UserConsent.Edit.prototype.onDataProviderUrlClick=function(){BX.SidePanel.Instance.open(this.dataProviderUrlNode.dataset.href)};BX.Main.UserConsent.Edit.prototype.onTypeChange=function(){var t=this.typeSelectorNode.options[this.typeSelectorNode.selectedIndex];var e=t.getAttribute("data-bx-type");var i=t.getAttribute("data-bx-lang");var o=t.getAttribute("data-bx-supp-provider")==="Y";var n=t.getAttribute("data-bx-agreement-text");this.typeViewNode.style.display=n?"":"none";this.typeViewNode.setAttribute("data-bx-text",n);if(e==="C"&&!i&&this.initialLang){i=this.initialLang}this.typeNode.value=e;this.langNode.value=i;this.dataProviderNode.style.display=o?"":"none";this.fieldListNodes.forEach(function(t){t.style.display=this.isTypeVisible(t)?"":"none"}.bind(this))};BX.Main.UserConsent.Edit.prototype.isTypeVisible=function(t){var e=t.getAttribute("data-bx-type");var i=t.getAttribute("data-bx-lang");return this.typeNode.value===e&&(!i||this.langNode.value===i)};BX.Main.UserConsent.Edit.prototype.showAgreementText=function(){var t=this.typeViewNode.getAttribute("data-bx-text");if(!t){return}if(!this.agreementViewPopup){var e=document.createElement("TEXTAREA");BX.addClass(e,"main-user-consent-edit-popup-textarea");e.disabled=true;this.agreementViewPopupContentNode=e;this.agreementViewPopup=BX.PopupWindowManager.create("main-user-consent-edit-view-agreement",null,{titleBar:this.mess.viewTitle,content:this.agreementViewPopupContentNode,autoHide:true,lightShadow:true,closeByEsc:true,closeIcon:true,overlay:{backgroundColor:"black",opacity:500},buttons:[new BX.PopupWindowButton({text:this.mess.close,events:{click:function(){this.popupWindow.close()}}})]})}this.agreementViewPopupContentNode.textContent=t;this.agreementViewPopup.show()};BX.Main.UserConsent.Edit.prototype.showFieldsDataProvider=function(t,e){var i="data-bx-is-data-prov-hide";var o=function(t,e){e.node.setAttribute(i,t?"N":"Y");e.view.node.style.display=!t?"":"none";e.toggledNode.style.display=t?"":"none";e.inputNode.disabled=!t};var n=this.getFields(this.container);n.filter((function(t){return t.node.getAttribute(i)=="Y"})).forEach(o.bind(this,true));if(!t){return}t.forEach((function(t){n.filter((function(e){return t.CODE==e.code})).forEach((function(i){i.view.nameNode.textContent=e.name.trim()+":";i.view.valueNode.textContent=t.VALUE;o(false,i)}))}))};BX.Main.UserConsent.Edit.prototype.getFields=function(t){return this.getFieldNodes(t).map((function(t){return{code:t.getAttribute("data-bx-field"),node:t,inputNode:t.querySelector("[data-bx-input]"),view:{node:t.querySelector("[data-bx-view]"),nameNode:t.querySelector("[data-bx-view-name]"),valueNode:t.querySelector("[data-bx-view-value]")},togglerNode:t.querySelector("[data-bx-toggler]"),toggledNode:t.querySelector("[data-bx-toggled]")}}))};BX.Main.UserConsent.Edit.prototype.getFieldNodes=function(t){var e=t.querySelectorAll("[data-bx-field]");return BX.convert.nodeListToArray(e)}})();
//# sourceMappingURL=script.map.js